<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>主页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/admin/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
</head>

<body class="layui-layout-body">
<div class="layui-row">
    <div class="layui-col-md2  formbox " style="margin-top: 10px">

    </div>

    <div class="layui-fluid layui-col-md8 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-form">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">时间区间:</label>
                                    <div class="layui-input-inline">
                                        <input type="text" style="size: 100px" class="layui-input" id="beginTime" placeholder="开始时间">
                                    </div>
                                    <div class="layui-form-mid">
                                        -
                                    </div>
                                    <div class="layui-input-inline">
                                        <input style="size: 100px" type="text" class="layui-input" id="endTime" placeholder="结束时间">
                                    </div>
                                </div>
                            </div>
                        </div>



                    </div>



                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button type="button" class="layui-btn" id="btnAdd"
                                        style="margin-left:10%;width: 100px">
                                    保存
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="layui-col-md2 formbox">

    </div>
</div>
</body>
</html>

<script>
    var $ = layui.$;
    var form = layui.form;

    $(function(){
        $.ajax({
            url:'/system/getDownTime',
            success:function(data){
                $("#beginTime").val(data.data.beginTime);
                $("#endTime").val(data.data.endTime);

            }
        });
    });

    $("#btnAdd").click(function () {

        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();
        if (beginTime=="" || endTime=="")
        {
            layer.msg("不能为空");
            return false;
        }
        if (isNaN(beginTime) || isNaN(endTime))
        {
            layer.msg("只能是数字");
            return false;
        }
        if (beginTime<0 || endTime<0){
            layer.msg("不能小于0");
            return false;
        }

        $.ajax({
            url: '/system/saveDownTime',
            data: {beginTime: beginTime, endTime: endTime},
            async: true,
            success: function (data) {

                if (data.code == 200) {
                    layer.msg("修改成功", {icon: 1, time: 1000});
                    return false;
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                    return false;
                }

            }
        });


    });
</script>

